package org.veridiandynamics.client.view;

import java.awt.CardLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.veridiandynamics.server.dao.HibernateDriver;
import org.veridiandynamics.server.dao.Queryprocessor;
import org.veridiandynamics.server.domain.Admin;
import org.veridiandynamics.server.domain.Doctor;
import org.veridiandynamics.server.domain.Nurse;
import org.veridiandynamics.server.domain.Patient;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

/**
 * @author Talia
 *
 * This creates the panel where system administrators can manage account suspension.
 */
public class SuspendAccountsPanel extends JPanel {

	private Container basePanel;
	private CardLayout c1;
	private JTextField textField;
	private JTextField textField_2;
	private JTextField userField1;
	private JTextField userField2;

	/**
	 * Constructor for panel. 
	 * @param c1 card layout
	 * @param container container
	 */
	public SuspendAccountsPanel(final CardLayout c1, final Container container)
	{
		this.c1 = c1;
		this.basePanel = container;
		MainWindow.welcomeMessage.setText("Suspend/unsuspend accounts");
		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
				new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));

		JLabel lblSuspendAccount = new JLabel("1.  Suspend account");
		add(lblSuspendAccount, "4, 4");

		JLabel lblEnterUsername = new JLabel("Enter username");
		add(lblEnterUsername, "4, 6");

		userField1 = new JTextField();
		add(userField1, "4, 8, fill, default");
		userField1.setColumns(10);

		JButton btnSubmit = new JButton("Submit");
		btnSubmit.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				String username = userField1.getText();
				Queryprocessor.suspendUser(username, true);
			}
		});


		add(btnSubmit, "8, 8");

		JLabel lblUnsuspendAccount = new JLabel("2.  Unsuspend account");
		add(lblUnsuspendAccount, "4, 12");

		JLabel lblEnterUsername_1 = new JLabel("Enter username");
		add(lblEnterUsername_1, "4, 14");

		userField2 = new JTextField();
		add(userField2, "4, 16, fill, default");
		userField2.setColumns(10);

		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				c1.first(basePanel);
			}
		});

		JButton btnSubmit_1 = new JButton("Submit");
		btnSubmit_1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				String username = userField2.getText();
				Queryprocessor.suspendUser(username, false);
			}
		});

		add(btnSubmit_1, "8, 16");
		add(btnBack, "12, 22");
	}

}
